package com.nage.engine;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class Main extends Activity {

	public static GameEngine engine;
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
              
        engine = new GameEngine();
        try {
        	Log.d("Main", "Initialise!");
			engine.initialise(this);
		} catch (Exception e) {
			Log.e("Main", "CRITICAL ERROR - SHUTTING DOWN: "+e.getMessage());
			throw new IllegalStateException(e.getMessage());
		}
        
    }
    
    @Override
    protected void onStart() {
    	super.onStart();
    	Log.d("Main", "Starting");
    	Statistics.reset();
    }
    
    @Override
    protected void onRestart() {
    	super.onRestart();
    	Log.d("Main", "Restarting");
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        engine.onPause();
        Log.d("Main", "Pausing");
    }

    @Override
    protected void onResume() {
        super.onResume();
        engine.onResume();
        Log.d("Main", "Resuming");
    }
    
    @Override
    protected void onStop() {
    	super.onStop();
    	Log.d("Main", "Stopping");
    	Statistics.results();
    }
    
    @Override
    protected void onDestroy() {
    	super.onDestroy();
    	Log.d("Main", "Destroying");
    }

}

// LESSON LEARNED TODAY: STATIC FIELDS NEED TO BE MANAGED MANUALLY 
// WITH REGARDS TO ACTIVITY LIFESPAN - onCreate() on Destroy() etc.